package com.yuanchu.store.controller;

import com.yuanchu.common.utils.PageResult;
import com.yuanchu.common.utils.R;
import com.yuanchu.common.validator.ValidationGroups;
import com.yuanchu.store.dto.EditStoreUserParamsDto;
import com.yuanchu.store.dto.QueryPageParams;
import com.yuanchu.store.dto.UserInfoDto;
import com.yuanchu.store.entity.YoshopStoreUserEntity;
import com.yuanchu.store.service.YoshopStoreUserService;
import com.yuanchu.store.utils.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 商家用户记录表
 *
 * @author adan
 * @email 2028038953@gmail.com
 * @date 2023-12-19 20:57:22
 */
@Api(tags = "商家用户接口", description = "StoreUserController")
@RestController
@RequestMapping("user")
public class StoreUserController {
    @Resource
    private YoshopStoreUserService storeUserService;
    Integer storeId = 10001;

    // /store/user/list?page=1
    @ApiOperation("查询商家管理员列表")
    @GetMapping("/list")
    public R getStoreUserList(QueryPageParams params) {
        PageResult<YoshopStoreUserEntity> pageResult =  storeUserService.queryStoreUserList(params, storeId);
        return R.ok().putPage("data", pageResult);
    }
    @ApiOperation("编辑商家管理员")
    @PostMapping("/edit")
    public R editStoreUser(@RequestBody @Validated({ValidationGroups.Update.class}) EditStoreUserParamsDto params) {
        return storeUserService.editStoreUser(params, storeId);
    }
    @ApiOperation("删除商家管理员")
    @PostMapping("/delete")
    public R deleteStoreUser(@RequestBody @Validated({ValidationGroups.Delete.class}) EditStoreUserParamsDto params) {
        return storeUserService.deleteStoreUser(params.getUserId(), storeId);
    }


    @GetMapping("/all")
    public R getUserGrade() {
        // userGradeService.findAll()
        // return R.ok().put("list", );
        return R.ok();
    }

    @GetMapping("/info")
    public R userInfo() {
        SecurityUtil.YoshopStoreUserEntity user = SecurityUtil.getUser();
        Integer userId = user.getStoreUserId();
        UserInfoDto userInfoDto = storeUserService.getUserInfo(userId);
        return R.ok().put("data", userInfoDto);
    }



}
